package com.mobi.cacti.ns.view.tab;

import org.holoeverywhere.app.Fragment;

import com.mobi.cacti.R;

import android.support.v4.app.FragmentTransaction;
import android.util.Log;

public class BaseContainerFragment extends Fragment {
	
	public void replaceFragment(Fragment fragment, boolean addToBackStack) {
		String tag = fragment.getClass().getName();
		
		if (getChildFragmentManager().findFragmentByTag(tag) != null) {
			return;
		}
		
		FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
		if (addToBackStack) {
			transaction.addToBackStack(null);
		}
		
		transaction.replace(R.id.container_framelayout, fragment, tag);
		transaction.commit();
		getChildFragmentManager().executePendingTransactions();
	}
	
	public boolean popFragment() {
		Log.e("test", "pop fragment: " + getChildFragmentManager().getBackStackEntryCount());
		boolean isPop = false;
		if (getChildFragmentManager().getBackStackEntryCount() > 0) {
			isPop = true;
			getChildFragmentManager().popBackStack();
		}
		return isPop;
	}
	
}
